package structure.AdapterPattern.practice;

import java.awt.event.WindowAdapter;

/**
 * 适配器模式
 * 模拟场进：在 LINUX 上运行 WINDOWS 程序。
 * */
public class AdapterPattern{
    public static void main(String[] args) {
        ILinux linux = new Linux();
        linux.run("LINUX");
        linux.run("WINDOWNS");
    }
}

interface ILinux{
    void run(String pam);
}
interface IWindowns{
    void run();
}

class Linux implements ILinux{

    private WindownsToLinuxAdater windownsToLinuxAdater;

    @Override
    public void run(String pam) {
        if ("LINUX".equals(pam)) {
            System.out.println("LINUX 程序");
            return;
        }
        if ("WINDOWNS".equals(pam)){
            windownsToLinuxAdater = new WindownsToLinuxAdater(pam);
            windownsToLinuxAdater.run(pam);
        }
    }

}
class Windowns implements IWindowns{
    @Override
    public void run(){
        System.out.println("Windowns 程序");
    }
}

class WindownsToLinuxAdater implements ILinux{

    private IWindowns windowns;

    public WindownsToLinuxAdater(String pam){
        if ("WINDOWNS".equals(pam)){
            windowns = new Windowns();
        }
    }

    @Override
    public void run(String pam) {
        windowns.run();
    }
}


